{extend name="public:layout" /}
{block name="title"}代码生成器{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}">数据表列表</a></li>
                <li class="active">模型生成</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">命名空间</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入命名空间" name="namespace"
                               value="{$info.namespace}" datatype="*"/>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">模型名称</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入模型名称" name="model"
                               value="{$info.model}" datatype="*"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">继承基类</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入继承基类" name="base_model"
                               value="{$info.base_model}" datatype="*"/>
                        <p class="help-block">继承基类以"\"分隔</p>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">保存路径</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入保存路径" name="save_path"
                               value="{$info.save_path}" datatype="*"/>
                        <p class="help-block">路径从网站根目录开始计算，以"/"结尾</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">自动写入时间戳</label>
                    <div class="col-sm-4">
                        <label class="radio-inline i-checks">
                            <input type="radio" name="auto_write_timestamp" value="true"
                                   {eq name="info.auto_write_timestamp" value="true"}checked{/eq} /> 是
                        </label>
                        <label class="radio-inline i-checks">
                            <input type="radio" name="auto_write_timestamp" value="false"
                                   {eq name="info.auto_write_timestamp" value="false"}checked{/eq} /> 否
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">类型转换</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" name="type_config" rows="5">{$info.type_config}</textarea>
                        <p class="help-block">对应模型中type定义，一行一个规则。涉及多选元素时候一般设置对应字段为array</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">获取器修改器</label>
                    <div class="col-sm-10">
                        <table class="table table-bordered">
                            <tr>
                                <th width="140">字段说明</th>
                                <th>字段名</th>
                                <th>字段类型</th>
                                <th>允许空</th>
                                <th>字段编码</th>
                                <th width="160">获取器</th>
                                <th width="160">修改器</th>
                            </tr>
                            {volist name="fields" id="vo"}
                            <tr>
                                <td>
                                    {$vo.column_comment}
                                </td>
                                <td>
                                    {$vo.column_name}
                                </td>
                                <td>{$vo.column_type}</td>
                                <td>{$vo.is_nullable}</td>
                                <td>{notempty name="vo.collation_name"}{$vo.character_set_name}({$vo.collation_name}){/notempty}</td>
                                <td>
                                    <label class="radio-inline i-checks">
                                        <input type="radio" name="get[{$vo.column_name}]" value="true"> 生成
                                    </label>
                                    <label class="radio-inline i-checks">
                                        <input type="radio" name="get[{$vo.column_name}]" value="false" checked> 忽略
                                    </label>
                                </td>
                                <td>
                                    <label class="radio-inline i-checks">
                                        <input type="radio" name="set[{$vo.column_name}]" value="true"> 生成
                                    </label>
                                    <label class="radio-inline i-checks">
                                        <input type="radio" name="set[{$vo.column_name}]" value="false" checked> 忽略
                                    </label>
                                </td>
                            </tr>
                            {/volist}
                        </table>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" id="btnSub" type="button">保存内容</button>
                        <a href="{:url('index')}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
    <script>
        $(function () {
            iCheck();
            In('chosen',function () {
                $('.chosen-select').chosen();
            })
            ajaxSubForm('#btnSub',function (res) {
                if(res.code==1){ //文件不存在
                    layer.confirm('确认要生成'+res.msg+'吗？', function(){
                        buildController();
                    });
                }else{
                    layer.confirm('该模型文件已存在，是否覆盖？', function(){
                        buildController();
                    });
                }
            });
        })
        //生成控制器
        function buildController() {
            var url="{:url('code.build/model')}";
            var tableName="{$Request.param.table_name}";
            getAjax(url,{table_name:tableName},function (res) {
                if(res.code==1){
                    location.href=res.url;
                }else{
                    layer.alert(res.msg);
                }
            })
        }
    </script>
{/block}